<script type="text/javascript">
	$(document).ready(function() {
			$(".delete_phone").click(function(){
				var ownIndex = $(this).attr('id');
				var iii = ownIndex;
				if(ownIndex == indexPhone){
					//$(".w_list_phone fieldset::nth-child("+ownIndex+")").replaceWith('');
					$(".w_list_phone fieldset#fi"+ownIndex).replaceWith('');
					indexPhone--;
				}else{
					//var lastPh = $(".w_list_phone fieldset::nth-child("+indexPhone+")");
					var lastPh = $(".w_list_phone fieldset#fi"+indexPhone);
					
					lastPh.find("input[type=checkbox],input[type=text]").each(function(){
			     		var name = $(this).attr('name');
			     		name = name.substr(name.indexOf('-'), name.length);
			     		$(this).attr('name',iii+name);
     					$(this).attr('class',iii+'-need_check_phone_language');
     					$(this).addClass('info_bull');
			     	});
			     	lastPh.find("input[type=button]").each(function(){
			     		$(this).removeClass('delete_phone'+indexPhone);
			     		$(this).addClass('delete_phone'+iii);
			     		$(this).attr('id',iii);
			     	});
			     	//$(".w_list_phone fieldset::nth-child("+ownIndex+")").replaceWith('');
			     	$(".w_list_phone fieldset#fi"+ownIndex).replaceWith('');
			     	lastPh.attr('id',"fi"+iii);
			     	indexPhone--;
				}
				
			});
		$(".add_more_phone_speak").click(function(){
		    	var alt = $(this).prev().children().children();
		    	var Othis = $(this);
		    	var language_code = $("html").attr('xml:lang');
		    	var div = 				  '<div id="image_link">'+
						                  '<dl class="table-display">' +
						                  '<dd><input type="text" name="debut_nom_serveur" id="__editor_upload_input" size="46" /></dd>'+
						                  '<dd><select id="__editor_upload_select" name="__editor_upload_select" size="8" style="width:301px;padding-left:5px;" class="obli"></select></dd>'+
						                  '</dl>'+                  
						                  '<input type="button" id="__editor_upload_insert" name="__editor_upload_insert" value="Insert" class="bouton" />'+
						                  '</div>';
				                  
                    					
				         $.jPopup.show("Plese Select language:", div, 320, 190);
						 $.ajax({
							   url : '../_ajax/inscription/get_list_language.php',
							   type: "POST",
							   data: "debut_nom_serveur="+$('#__editor_upload_input').val()+"&language="+language_code+"&notin="+notInLanguage+"&profil='ture'",
							   success: function(data_responed){
					                $('#__editor_upload_select').html(data_responed);
							   }
							});
						$('#__editor_upload_input').keyup(function(){
						 if (timeout) clearTimeout(timeout);
									timeout = setTimeout(function(){
							        $.ajax({
									   url : '../_ajax/inscription/get_list_language.php',
									   type: "POST",
									   data: "debut_nom_serveur="+$('#__editor_upload_input').val()+"&language="+language_code+"&notin="+notInLanguage+"&profil='ture'",
									   success: function(data_responed){
							                $('#__editor_upload_select').html(data_responed);
									   }
									});
								}, delay_search);
						 });
						 $("#__editor_upload_insert").click(function(){
						 	if($("#__editor_upload_select").val() > 0){
						 		
							 	var val = $("#__editor_upload_select").val();
							 	var text = $("#__editor_upload_select option:selected").text();
							 	var alter = alt.attr('alt');
						 		
						 		var wrap_chph = Othis.parent().prev();
						 		//a.append(h);
						 		var inde = (Othis.attr('id')).match(/[0-9]+/);
						 		var put=1;
						 		var h = '<span id="each_ph"><input type="checkbox" checked="true" alt="'+alter+'" id="'+inde+'-check_phones'+val+'" name="'+inde+'-check_phones'+val+'" class="'+inde+'-need_check_phone_language">&nbsp;'+text+'&nbsp;</span>';
						 		$("input[type=checkbox]",wrap_chph).each(function(j){
						 			var nameHas = inde+'-check_phones'+val;
						 			//$("input[type=checkbox]",this).each(function(j){
						 				if(nameHas == $(this).attr('name')) return put=0;
						 			//});
						 			
						 		});
						 		if(put==1) wrap_chph.append(h);
						 		$.jPopup.remove();
						 		
						 		notInLanguage=notInLanguage+','+val;
						 		$('.info_bull').mouseover(function(e){
									setInfoBulles(this);
									setInfoBullesPosition(this);
								}).mouseout(function(){
									$('.info_div').hide();			
								});
						 	}
			}); 
    });
	});
</script>